var ecommRecordAddCtrl  = new XFApp.client();
$.views.converters({
	
});

XFApp.client.prototype.ecommRecordAdd = {
		successCode : 10000,	
		urlItems : {			
			saveStoreURL: basePath+"/userCenter/ecommerceRecord/save",
		},
		
		formValidate : function(){
			$("#addForm").validate({
		        rules: {
		        	customerCode: "required",
		        	customerName: "required",
		        	agentCode: "required",
		        	agentName: "required",
		        	appUId: "required",
		        	appUName: "required",
		        	ebpCode: "required",
		        	ebpName: "required",
		        	ebcCode: "required",
		        	ebcName: "required",
		        	classifyCode: "required",
		        	classifyName: "required",
		        	interfaceCode: "required",
		        	imagePath: "required"
				  },
				 messages: {
					 customerCode: "请填写客户代码",
			         customerName: "请填写企业名称",
			         agentCode: "请填写申报类企业代码",
			         agentName: "请填写申报类企业名称",
			         appUId: "请填写持卡人编号",
			         appUName: "请填写持卡人姓名",
			         ebpCode: "请填写电商平台代码",
			         ebpName: "请填写电商平台名称",
			         ebcCode: "请填写电商企业代码",
			         ebcName: "请填写电商企业名称",
			         classifyCode: "请填写预归类企业代码",
			         classifyName: "请填写预归类企业名称",
			         interfaceCode: "请填写线上订单接口编号",
			         imagePath: "请上传海关备案证书图片"		        	    
			         }
		    });
			$("#addForm").validate();
		},
		
		event : function (){			
			_this = this;
			
			$("#submitBtn").on("click",function(){				
				if($("#addForm").validate().form()){
					ecommRecordAddCtrl.ecommRecordAdd.submit();
				}				
			});
			//表单验证
			_this.formValidate();	
		},		
		
		
		submit : function (){		    
			
			var params = [];
			
			var paramType = {name:'',value:''};			
			$("#inputDiv input[type='text']").each(function() {
				if(!!$(this).attr("name")){
					var param = {name:'',value:''};
					param.name=$(this).attr("name");
					param.value= $(this).val();
					params.push(param);					
				}
			});	
			
			//基于ajaxfileUpload.js实现
			$.ajaxFileUpload({
				url : _this.urlItems.saveStoreURL,
				secureuri : false,
				data:params,
				fileElementId : 'certPath',//现使用方法
				dataType : 'json',
				success : function(data) {
					if (data.code == _this.successCode) {
						window.webDialogUtil.alert("提示",data.msg);	
					    $('#addForm')[0].reset();  		
						//window.location.href= basePath+"/userCenter/ecommerceRecord/index" ;
					} else {
						window.webDialogUtil.alert("提示",data.msg);
					}
				},
				error : function(data, status, e){
					window.webDialogUtil.alert("提示",data.msg);
				}
			});
		},
	
		
},

$(function(){	
	ecommRecordAddCtrl.ecommRecordAdd.event();
	
});